var Url = {
    ui: {
        iframe: "/iframe.html",
        login: "/login.html"
    },

    websocket: "/api/websocket",
    unsupported: "/api/unsupported",

    fileList: "/api/file",
    fileDetail: "/api/file/{uuid}/get",
    fileCreate: "/api/file",
    fileModify: "/api/file/{uuid}",
    fileRemove: "/api/file/{uuid}",
    fileConfirm: "/api/file/{uuid}/confirm",
    fileUpload: "/api/file/{uuid}/upload",
    fileDownload: "/api/file/{uuid}/download",

    serviceList: "/api/service",

    baseService: {
        session: "/api/base-service/user/session",
        heartbeat: "/api/base-service/user/heartbeat",
        login: "/api/base-service/login",
        logout: "/api/base-service/logout",

        userSearchByKeyword: "/api/base-service/user/search/keyword",
        userPage: "/api/base-service/user",
        userCreate: "/api/base-service/user",
        userModify: "/api/base-service/user/{id}",
        userRemove: "/api/base-service/user/{id}",
        userDetail: "/api/base-service/user/{id}",
        userOnline: "/api/base-service/user/online",

        rolePageByKeyword: "/api/base-service/role/search/keyword",
        rolePage: "/api/base-service/role",
        roleCreate: "/api/base-service/role",
        roleModify: "/api/base-service/role/{id}",
        roleRemove: "/api/base-service/role/{id}",
        roleDetail: "/api/base-service/role/{id}",

        letterPageByKeyword: "/api/base-service/letter/search/keyword",
        letterPage: "/api/base-service/letter",
        letterCreate: "/api/base-service/letter",
        letterModify: "/api/base-service/letter/{id}",
        letterRemove: "/api/base-service/letter/{id}",
        letterDetail: "/api/base-service/letter/{id}",
        letterSetReaded: "/api/base-service/letter/{id}/readed",
        letterSetUnread: "/api/base-service/letter/{id}/unread",
        letterSetAllReaded: "/api/base-service/letter/readed",
        letterSetAllUnread: "/api/base-service/letter/unread",
        letterRemoveAll: "/api/base-service/letter",
        letterRemoveReaded: "/api/base-service/letter/readed",
        letterRemoveUnread: "/api/base-service/letter/unread",

        taskPageByKeyword: "/api/base-service/task/search/keyword",
        taskDetail: "/api/base-service/task/{id}",

        permissionPage: "/api/base-service/permission",

        scriptPageByKeyword: "/api/base-service/script/search/keyword",
        scriptPage: "/api/base-service/script",
        scriptType: "/api/base-service/script/type",
        scriptCreate: "/api/base-service/script",
        scriptModify: "/api/base-service/script/{id}",
        scriptRemove: "/api/base-service/script/{id}",
        scriptDetail: "/api/base-service/script/{id}",
    },

    dataService: {
        dataSourceSearchByKeyword: "/api/data-service/ds/search/keyword",
        dataSourceTypePage: "/api/data-service/ds/type",
        dataSourceDataTypePage: "/api/data-service/ds/type/{type}/type",
        dataSourceCasePage: "/api/data-service/ds/case",
        dataSourcePage: "/api/data-service/ds",
        dataSourceCreate: "/api/data-service/ds",
        dataSourceModify: "/api/data-service/ds/{id}",
        dataSourceRemove: "/api/data-service/ds/{id}",
        dataSourceDetail: "/api/data-service/ds/{id}",
        dataSourceTimeline: "/api/data-service/ds/{id}/timeline",
        dataSourceClone: "/api/data-service/ds/{id}/clone",
        dataSourceSuper: "/api/data-service/ds/{id}/super",
        dataSourceExecute: "/api/data-service/ds/{id}/execute",
        dataSourceQuery: "/api/data-service/ds/{id}/query",
        dataSourceMore: "/api/data-service/ds/{id}/more",
        dataSourceSqlCreateTable: "/api/data-service/ds/{id}/table/{name}/sql/create",
        dataSourceSqlModifyTable: "/api/data-service/ds/{id}/table/{name}/sql/modify",
        dataSourceSqlRemoveTable: "/api/data-service/ds/{id}/table/{name}/sql/remove",
        dataSourceSqlCreateColumn: "/api/data-service/ds/{id}/table/{tn}/column/{cn}/sql/create",
        dataSourceSqlModifyColumn: "/api/data-service/ds/{id}/table/{tn}/column/{cn}/sql/modify",
        dataSourceSqlRemoveColumn: "/api/data-service/ds/{id}/table/{tn}/column/{cn}/sql/remove",

        dataAgentSearchByKeyword: "/api/data-service/da/search/keyword",
        dataAgentSearchByType: "/api/data-service/da/search/type",
        dataAgentPage: "/api/data-service/da",
        dataAgentCreate: "/api/data-service/da",
        dataAgentModify: "/api/data-service/da/{id}",
        dataAgentRemove: "/api/data-service/da/{id}",
        dataAgentDetail: "/api/data-service/da/{id}",

        dataProjectSearchByKeyword: "/api/data-service/dp/search/keyword",
        dataProjectPage: "/api/data-service/dp",
        dataProjectCreate: "/api/data-service/dp",
        dataProjectModify: "/api/data-service/dp/{id}",
        dataProjectRemove: "/api/data-service/dp/{id}",
        dataProjectDetail: "/api/data-service/dp/{id}",
        dataProjectTimeline: "/api/data-service/dp/{id}/timeline",
        dataProjectEnable: "/api/data-service/dp/{id}/enable",
        dataProjectDisable: "/api/data-service/dp/{id}/disable",
        dataProjectInit: "/api/data-service/dp/{id}/init",
        dataProjectUpgrade: "/api/data-service/dp/{id}/upgrade",

        dataBackupPlanSearchByKeyword: "/api/data-service/dbp/search/keyword",
        dataBackupPlanPage: "/api/data-service/dbp",
        dataBackupPlanCreate: "/api/data-service/dbp",
        dataBackupPlanModify: "/api/data-service/dbp/{id}",
        dataBackupPlanRemove: "/api/data-service/dbp/{id}",
        dataBackupPlanDetail: "/api/data-service/dbp/{id}",
        dataBackupPlanEnable: "/api/data-service/dbp/{id}/enable",
        dataBackupPlanDisable: "/api/data-service/dbp/{id}/disable",

        dataBackupHistorySearchByKeyword: "/api/data-service/dbh/search/keyword",
        dataBackupHistorySearchByDataSource: "/api/data-service/dbh/search/ds",
        dataBackupHistoryPage: "/api/data-service/dbh",
        dataBackupHistoryCreate: "/api/data-service/dbh",
        dataBackupHistoryModify: "/api/data-service/dbh/{id}",
        dataBackupHistoryRemove: "/api/data-service/dbh/{id}",
        dataBackupHistoryDetail: "/api/data-service/dbh/{id}",
        dataBackupHistoryDownload: "/api/data-service/dbh/{id}/download",

        dataRecoveryHistorySearchByKeyword: "/api/data-service/drh/search/keyword",
        dataRecoveryHistoryPage: "/api/data-service/drh",
        dataRecoveryHistoryCreate: "/api/data-service/drh",
        dataRecoveryHistoryModify: "/api/data-service/drh/{id}",
        dataRecoveryHistoryRemove: "/api/data-service/drh/{id}",
        dataRecoveryHistoryDetail: "/api/data-service/drh/{id}",

        dataComparePlanSearchByKeyword: "/api/data-service/dcp/search/keyword",
        dataComparePlanPage: "/api/data-service/dcp",
        dataComparePlanCreate: "/api/data-service/dcp",
        dataComparePlanModify: "/api/data-service/dcp/{id}",
        dataComparePlanRemove: "/api/data-service/dcp/{id}",
        dataComparePlanDetail: "/api/data-service/dcp/{id}",
        dataComparePlanEnable: "/api/data-service/dcp/{id}/enable",
        dataComparePlanDisable: "/api/data-service/dcp/{id}/disable",

        dataCompareHistorySearchByKeyword: "/api/data-service/dch/search/keyword",
        dataCompareHistoryPage: "/api/data-service/dch",
        dataCompareHistoryTable: "/api/data-service/dch/{id}/table",
        dataCompareHistoryColumn: "/api/data-service/dch/{id}/column",
        dataCompareHistoryCreate: "/api/data-service/dch",
        dataCompareHistoryModify: "/api/data-service/dch/{id}",
        dataCompareHistoryRemove: "/api/data-service/dch/{id}",
        dataCompareHistoryDetail: "/api/data-service/dch/{id}",
        dataCompareHistoryTruncate: "/api/data-service/dch",

        dataTransporterPlanSearchByKeyword: "/api/data-service/dtp/search/keyword",
        dataTransporterPlanPage: "/api/data-service/dtp",
        dataTransporterPlanCreate: "/api/data-service/dtp",
        dataTransporterPlanModify: "/api/data-service/dtp/{id}",
        dataTransporterPlanRemove: "/api/data-service/dtp/{id}",
        dataTransporterPlanDetail: "/api/data-service/dtp/{id}",
        dataTransporterPlanEnable: "/api/data-service/dtp/{id}/enable",
        dataTransporterPlanDisable: "/api/data-service/dtp/{id}/disable",

        dataTransporterHistorySearchByKeyword: "/api/data-service/dth/search/keyword",
        dataTransporterHistoryPage: "/api/data-service/dth",
        dataTransporterHistoryTable: "/api/data-service/dth/{id}/table",
        dataTransporterHistoryCreate: "/api/data-service/dth",
        dataTransporterHistoryModify: "/api/data-service/dth/{id}",
        dataTransporterHistoryRemove: "/api/data-service/dth/{id}",
        dataTransporterHistoryDetail: "/api/data-service/dth/{id}",
        dataTransporterHistoryTruncate: "/api/data-service/dth",

        dataStatsCountDataSourceByStatus: "/api/data-service/stats/count-data-source-by-status",
        dataStatsCountDataSource: "/api/data-service/stats/count-data-source",
        dataStatsCountDataProject: "/api/data-service/stats/count-data-project",
        dataStatsCountDataAgent: "/api/data-service/stats/count-data-agent",
        dataStatsCountDataBackupPlan: "/api/data-service/stats/count-data-backup-plan",
        dataStatsCountDataBackupHistory: "/api/data-service/stats/count-data-backup-history",
        dataStatsCountDataRecoveryHistory: "/api/data-service/stats/count-data-recovery-history",
        dataStatsCountDataComparePlan: "/api/data-service/stats/count-data-compare-plan",
        dataStatsCountDataCompareHistory: "/api/data-service/stats/count-data-compare-history",
        dataStatsSumDataTaskByDay: "/api/data-service/stats/sum-data-task-by-day",
    },

    dockerService: {
        dockerServerSearchByKeyword: "/api/docker-service/server/search/keyword",
        dockerServerPage: "/api/docker-service/server",
        dockerServerCreate: "/api/docker-service/server",
        dockerServerModify: "/api/docker-service/server/{id}",
        dockerServerRemove: "/api/docker-service/server/{id}",
        dockerServerDetail: "/api/docker-service/server/{id}",

        dockerRegistrySearchByKeyword: "/api/docker-service/registry/search/keyword",
        dockerRegistryPage: "/api/docker-service/registry",
        dockerRegistryCreate: "/api/docker-service/registry",
        dockerRegistryModify: "/api/docker-service/registry/{id}",
        dockerRegistryRemove: "/api/docker-service/registry/{id}",
        dockerRegistryDetail: "/api/docker-service/registry/{id}",

        dockerImagePage: "/api/docker-service/image/page",
        dockerImageCreate: "/api/docker-service/image/create",
        dockerImageRemove: "/api/docker-service/image/remove",
        dockerImageDetail: "/api/docker-service/image/detail",
        dockerImageDownload: "/api/docker-service/image/download",
        dockerImagePush: "/api/docker-service/image/push",

        dockerNetworkSearchByKeyword: "/api/docker-service/network/search/keyword",
        dockerNetworkPage: "/api/docker-service/network",
        dockerNetworkCreate: "/api/docker-service/network",
        dockerNetworkRemove: "/api/docker-service/network/{id}",
        dockerNetworkDetail: "/api/docker-service/network/{id}",

        dockerContainerSearchByKeyword: "/api/docker-service/container/search/keyword",
        dockerContainerPage: "/api/docker-service/container",
        dockerContainerCreate: "/api/docker-service/container",
        dockerContainerRemove: "/api/docker-service/container/{id}",
        dockerContainerDetail: "/api/docker-service/container/{id}",
        dockerContainerStart: "/api/docker-service/container/{id}/start",
        dockerContainerStop: "/api/docker-service/container/{id}/stop",
        dockerContainerRestart: "/api/docker-service/container/{id}/restart",
        dockerContainerKill: "/api/docker-service/container/{id}/kill",
        dockerContainerPause: "/api/docker-service/container/{id}/pause",
        dockerContainerResume: "/api/docker-service/container/{id}/resume",
        dockerContainerRename: "/api/docker-service/container/{id}/rename",
        dockerContainerLog: "/api/docker-service/container/{id}/log",
        dockerContainerCpuDonut: "/api/docker-service/container/{id}/cpu/donut",
        dockerContainerCpuLine: "/api/docker-service/container/{id}/cpu/line",
        dockerContainerMemoryDonut: "/api/docker-service/container/{id}/memory/donut",
        dockerContainerMemoryLine: "/api/docker-service/container/{id}/memory/line",
    },

    automationService: {
        autoSshServerSearchByKeyword: "/api/automation-service/server/search/keyword",
        autoSshServerPage: "/api/automation-service/server",
        autoSshServerCreate: "/api/automation-service/server",
        autoSshServerModify: "/api/automation-service/server/{id}",
        autoSshServerRemove: "/api/automation-service/server/{id}",
        autoSshServerDetail: "/api/automation-service/server/{id}",

        autoTaskTemplateSearchByKeyword: "/api/automation-service/template/search/keyword",
        autoTaskTemplatePage: "/api/automation-service/template",
        autoTaskTemplateCreate: "/api/automation-service/template",
        autoTaskTemplateModify: "/api/automation-service/template/{id}",
        autoTaskTemplateRemove: "/api/automation-service/template/{id}",
        autoTaskTemplateDetail: "/api/automation-service/template/{id}",
        autoTaskTemplateArgType: "/api/automation-service/template/type/arg",
        autoTaskTemplateNodeType: "/api/automation-service/template/type/node",
        autoTaskTemplateStdinType: "/api/automation-service/template/type/stdin",
        autoTaskTemplateStdoutType: "/api/automation-service/template/type/stdout",

        autoTaskHistorySearchByKeyword: "/api/automation-service/history/search/keyword",
        autoTaskHistoryPage: "/api/automation-service/history",
        autoTaskHistoryCreate: "/api/automation-service/history",
        autoTaskHistoryModify: "/api/automation-service/history/{id}",
        autoTaskHistoryRemove: "/api/automation-service/history/{id}",
        autoTaskHistoryDetail: "/api/automation-service/history/{id}",
    }

};
var HttpMethod = {
    get: "GET",
    post: "POST",
    put: "PUT",
    patch: "PATCH",
    delete: "DELETE"
};
var ContentType = {
    json: "application/json",
    form: "multipart/form-data",
    xml: "application/xml",
    text: "text/html",
};
var DefaultHeaderImageForFrame = "adminLTE/img/avatar5.png";
var DefaultHeaderImageForChild = "../../adminLTE/img/avatar5.png";
var MaxPageSize = 0x7fffffff;
var Utils = {
    isEmpty: function (val) {
        if (val instanceof String || typeof (val) === "string") {
            return val === undefined || val === null || val === "";
        } else if (val instanceof Array) {
            return val === undefined || val === null || val.length === 0;
        } else {
            return val === undefined || val === null;
        }
    },
    notEmpty: function (val) {
        return this.isEmpty(val) === false;
    },
    isTrue: function (val) {
        if (this.isEmpty(val)) {
            return false;
        }
        if (val instanceof String || typeof (val) === "string") {
            return val === "true" || val === "True" || val === "TRUE";
        } else if (val instanceof Number || typeof (val) === "number") {
            return val > 0;
        } else if (val instanceof Boolean || typeof (val) === "boolean") {
            return val;
        } else {
            return val;
        }
    },
    isFalse: function (val) {
        return this.isTrue(val) === false;
    },
    getParams: function (href) {
        var reg = /\b(\w+)=([^\/&]*)/g;
        var value = {};
        href.replace(reg, function($0, $1, $2) {
            value[$1] = decodeURIComponent($2);
        });
        return value;
    },
    getHeadImageForFrame: function (img) {
        return Utils.isEmpty(img) ? DefaultHeaderImageForFrame : Url.fileDownload.replace("{uuid}", img);
    },
    getHeadImageForChild: function (img) {
        return Utils.isEmpty(img) ? DefaultHeaderImageForChild : Url.fileDownload.replace("{uuid}", img);
    }
};
var LocalStorageKey = {
    dockerContainerCreateSetting: "tool-box-docker-container-create-setting",
};
var Services = [
    {key: "CONFIG-CENTER", value: "系统配置中心", icon: "fa-cog"},
    {key: "SERVICE-CENTER", value: "系统注册中心", icon: "fa-registered"},
    {key: "GATEWAY-CENTER", value: "系统网关服务", icon: "fa-crop"},
    {key: "BASE-SERVICE", value: "系统管理服务", icon: "fa-cogs"},
    {key: "DATA-SERVICE", value: "数据管理服务", icon: "fa-cube"},
    {key: "DOCKER-SERVICE", value: "容器管理服务", icon: "fa-delicious"},
    {key: "AUTOMATION-SERVICE", value: "流程编排服务", icon: "fa-tasks"},
]
// ajax全局设定
$(document).on("ajaxError", function (event, xhr, options, exc) {
    if (xhr.status === 401) {
        window.location.href = Url.ui.login;
    } else {
        var error;
        if (xhr.responseJSON && xhr.responseJSON.message) {
            error = xhr.responseJSON.message;
        } else if (xhr.responseText) {
            error = xhr.responseText;
        } else if (xhr.statusText) {
            error = xhr.statusText
        } else if (xhr.statusMessage) {
            error = xhr.statusMessage
        } else {
            error = JSON.stringify(xhr);
        }
        toastr.error("[" + xhr.status + "] " + error);
    }
});
// 日期时间格式化
Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "H+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};